package com.ruoyi.origin.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.origin.domain.NewsOrigin;
import com.ruoyi.origin.service.INewsOriginService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 新闻来源Controller
 * 
 * @author lsx
 * @date 2025-01-16
 */
@RestController
@RequestMapping("/origin/origin")
public class NewsOriginController extends BaseController
{
    @Autowired
    private INewsOriginService newsOriginService;

    /**
     * 查询新闻来源列表
     */
    @PreAuthorize("@ss.hasPermi('origin:origin:list')")
    @GetMapping("/list")
    public TableDataInfo list(NewsOrigin newsOrigin)
    {
        startPage();
        List<NewsOrigin> list = newsOriginService.selectNewsOriginList(newsOrigin);
        return getDataTable(list);
    }

    /**
     * 导出新闻来源列表
     */
    @PreAuthorize("@ss.hasPermi('origin:origin:export')")
    @Log(title = "新闻来源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NewsOrigin newsOrigin)
    {
        List<NewsOrigin> list = newsOriginService.selectNewsOriginList(newsOrigin);
        ExcelUtil<NewsOrigin> util = new ExcelUtil<NewsOrigin>(NewsOrigin.class);
        util.exportExcel(response, list, "新闻来源数据");
    }

    /**
     * 获取新闻来源详细信息
     */
    @PreAuthorize("@ss.hasPermi('origin:origin:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(newsOriginService.selectNewsOriginById(id));
    }

    /**
     * 新增新闻来源
     */
    @PreAuthorize("@ss.hasPermi('origin:origin:add')")
    @Log(title = "新闻来源", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NewsOrigin newsOrigin)
    {
        return toAjax(newsOriginService.insertNewsOrigin(newsOrigin));
    }

    /**
     * 修改新闻来源
     */
    @PreAuthorize("@ss.hasPermi('origin:origin:edit')")
    @Log(title = "新闻来源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NewsOrigin newsOrigin)
    {
        return toAjax(newsOriginService.updateNewsOrigin(newsOrigin));
    }

    /**
     * 删除新闻来源
     */
    @PreAuthorize("@ss.hasPermi('origin:origin:remove')")
    @Log(title = "新闻来源", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(newsOriginService.deleteNewsOriginByIds(ids));
    }
}
